<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"   pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<c:url value="resources/css/item.css"/>" >
</head>
<h1>Edit product</h1>
<table class="search">
<tr>
	<th width="100">Name</th>
	<th width="100">Price</th>
	<th width="100">Stock</th>
</tr>
    
<c:forEach var="currentProduct" items="${products}" varStatus="status">
	 <form:form method="post" action = "" modelAttribute="product">
		 <form:hidden path="productId" value ="${currentProduct.productId}"/>
	    <tr>
		    <c:url var="prodUrl" value="/admin/product/edit" >
		 		<c:param name="productId" value="${currentProduct.productId}" />
		    </c:url>
		    <td>
		        <a href='<c:out value="${prodUrl}"/>'>${currentProduct.name}</a>
		    </td>
		   <td  style="text-align: center;"><form:input path="actualPrice" value="${currentProduct.actualPrice}"/></td>
		   <td  style="text-align: center;"><form:input path="stock" value="${currentProduct.stock}"/></td>
		   <td><input type="submit" value = "edit"> </td>
		   <td><form:errors path="actualPrice" cssClass="error"/></td>
		   <td><form:errors path="stock" cssClass="error"/></td>
	   </tr>
	</form:form>
</c:forEach>
</table>
<c:url var="addUrl" value="/admin/product/add" >
	<c:param name="categoryId" value="${categoryId}" />
</c:url>
 <a href='<c:out value="${addUrl}"/>'>add</a>
<table>
<tr>
<c:if test="${lastPageNum>1}">
<c:forEach var="i" begin="1" end="${lastPageNum}" varStatus="status">
	<c:url var="pageUrl" value="/admin/product" >
 		<c:param name="categoryId" value="${categoryId}" />
 		<c:param name="pageNum" value= "${i}" />
    </c:url>
    	<td><a href='<c:out value="${pageUrl}"/>'>${i}</a></td>	
</c:forEach>
</c:if>
</tr>
</table>
</html>